package org.hairball.analysis;

import java.util.HashMap;
import java.util.Map;

public class ASMClassDescriptorFilter implements ClassnameFilter {
    private static Map<String, String> shortcodes;

    static {
        shortcodes = new HashMap<String, String>();
        shortcodes.put("Z", "boolean");
        shortcodes.put("D", "double");
        shortcodes.put("I", "int");
        shortcodes.put("F", "float");
    }

    public String filter(String classname) {
        if (shortcodes.containsKey(classname)) {
            return shortcodes.get(classname);
        } else {
            String filtered = classname.replaceAll("/", ".");
            if (classname.indexOf("L") == 0) {
                filtered = filtered.substring(1, filtered.length());
            }

            if (classname.indexOf("[L") == 0) {
                filtered = filtered.substring(2, filtered.length());
            }

            if (classname.indexOf(";") != -1) {
                filtered = filtered.substring(0, filtered.length() - 1);
            }
            return filtered;
        }
    }
}
